package com.nmgdz.bigdata.controller;

import com.nmgdz.bigdata.entity.User;
import com.nmgdz.bigdata.service.RedisService;
import com.nmgdz.bigdata.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisSevice;

    @GetMapping("/gueryBuId")
    public String gueryById(int id) {
        String userStr = redisSevice.get(id+"");
        if (userStr == null){
            redisSevice.set(id + "",userService.gueryById(id).toString());
        }
        return userStr;


    }
    @PatchMapping("/save")
    public User saveUser(String name,int age){
        return userService.save(new User(name,age));
    }

}
